#ifndef PHYSICWORLD_H
#define PHYSICWORLD_H

#include "../common/Common.h"
#include "bodies/Body.h"
#include "bodies/Aabb.h"
#include "core/CollisionInfo.h"
#include "core/Collision.h"
#include <QMap>
#include <QSet>


class PhysicWorld {
public:
	PhysicWorld(Point* gravity);
	~PhysicWorld() {
		delete gravity;
		delete bodies;
	}
	void addBody(Body* body);

	void update();
	void update(float interval);
protected:
	void applyForceToBody(Body* body);
	void updateAllBodyStatusByAllForce();
	void calcAllBodyAabb();
	void checkAllCollision(QSet<CollisionInfo*>* collisionInfos);
	void responseCollision(QSet<CollisionInfo*>* collisionInfos);
	void checkCollisionForOthers(Body* body, CollisionInfo* collisionInfo);
	void releaseCollisionInfo();
	virtual void doUserCollisionEvent(CollisionInfo* collisiionInfo) {};

private:
	float interval = 0;
	Point* gravity = new Point();
	QMap<int, Body*>* bodies = new QMap<int, Body*>();
	QSet<CollisionInfo*>* collisionInfos = new QSet<CollisionInfo*>();

};

#endif PHYSICWORLD_H